package dao

import (
	"fmt"
	"github.com/go-redis/redis"
	"time"
)

func AddOrderInSet(orderSn string) error {
	data := make([]redis.Z, 1)
	score := time.Now().Add(6 * time.Second).Unix()
	fscore := float64(score)
	data = append(data, redis.Z{Score: fscore, Member: orderSn})
	result, err := rdb.ZAddNX(PENGDING_ORDER, data...).Result()
	if err != nil {
		return err
	}
	fmt.Println(result)
	return nil
}

func RedoOrder() []string{
	timeStamp := time.Now().Unix()
	ordsns, err := rdb.ZRange(PENGDING_ORDER, 0, timeStamp).Result()
	if err != nil {
		panic(err)
	}

	if len(ordsns) > 0 {
		_, err := rdb.SAdd(PROCESSING_ORDER, ordsns).Result()
		if err != nil {
			panic(err)
		}
		_, err = rdb.ZRem(PENGDING_ORDER, ordsns).Result()
		if err != nil {
			panic(err)
		}
	}
	return ordsns
}
